package com.example.demo.service;

import java.util.List;

import com.example.demo.entity.Category;
import com.example.demo.entity.Goods;
import com.example.demo.mapper.GoodsMapper;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * goodsService业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@Service
public class GoodsServiceImpl implements IGoodsService 
{
    @Autowired
    private GoodsMapper goodsMapper;

    /**
     * 查询goods
     * 
     * @param gid goods主键
     * @return goods
     */
    @Override
    public Goods selectGoodsByGid(Long gid)
    {
        return goodsMapper.selectGoodsByGid(gid);
    }



    /**
     * 查询goods列表
     * 
     * @param goods goods
     * @return goods
     */
    @Override
    public PageResult selectGoodsBypage(Goods goods, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> list = goodsMapper.selectGoodsList(goods);
        System.out.println(list.size());
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }
    @Override
    public List<Goods> selectGoodsList(Goods goods)
    {
        return goodsMapper.selectGoodsList(goods);
    }

    /**
     * 新增goods
     * 
     * @param goods goods
     * @return 结果
     */
    @Override
    public int insertGoods(Goods goods)
    {
        return goodsMapper.insertGoods(goods);
    }

    /**
     * 修改goods
     * 
     * @param goods goods
     * @return 结果
     */
    @Override
    public int updateGoods(Goods goods)
    {
        return goodsMapper.updateGoods(goods);
    }

    /**
     * 批量删除goods
     * 
     * @param gids 需要删除的goods主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGids(Long[] gids)
    {
        return goodsMapper.deleteGoodsByGids(gids);
    }

    /**
     * 删除goods信息
     * 
     * @param gid goods主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGid(Long gid)
    {
        return goodsMapper.deleteGoodsByGid(gid);
    }
}
